<template>
  <el-table-column :="attrs">
    <template #default="{ row }">
      <template v-if="linkType === TypeEnum.BUTTON">
        <ElButton type="primary" link @click="$emit('open-drawer', row)">{{ row[props.prop] }}</ElButton>
      </template>
      <template v-else>
        <ElLink type="primary" link @click="$emit('open-drawer', row)">{{ row[props.prop] }}</ElLink>
      </template>
    </template>
  </el-table-column>
</template>

<script setup lang="ts">
import {useAttrs} from 'vue'

const attrs = useAttrs()

enum TypeEnum {
  LINK = 'link',
  BUTTON = 'button',
}

const props = defineProps({
  prop: String,
  linkType: {
    type: String,
    default: TypeEnum.BUTTON,
    validator: (value: string) => {
      return Object.values(TypeEnum).includes(value as TypeEnum);
    }
  }
})

const emit = defineEmits(['open-drawer'])
</script>
